//
// File: welchparse.cpp
//
// MATLAB Coder version            : 5.4
// C/C++ source code generated on  : 23-Apr-2025 16:26:18
//

// Include Files
#include "welchparse.h"
#include "freqDomainHRV_data.h"
#include "freqDomainHRV_internal_types.h"
#include "hamming.h"
#include "ifWhileCond.h"
#include "psdoptions.h"
#include "rt_nonfinite.h"
#include "strcmp.h"
#include "validatestring.h"
#include "coder_array.h"
#include <cmath>
#include <math.h>
#include <string.h>

// Type Definitions
struct emxArray_char_T_1x15 {
  char data[15];
  int size[2];
};

struct cell_wrap_21 {
  emxArray_char_T_1x15 f1;
};

// Function Definitions
//
// Arguments    : const ::coder::array<double, 2U> &x1
//                double varargin_1
//                double varargin_2
//                double varargin_3
//                double varargin_4
//                const char varargin_5[8]
//                ::coder::array<double, 1U> &x
//                double *M
//                ::coder::array<double, 1U> &win
//                double *noverlap
//                double *k
//                double *L
//                struct_T *options
// Return Type  : void
//
namespace coder {
namespace signal {
namespace internal {
namespace spectral {
void welchparse(const ::coder::array<double, 2U> &x1, double varargin_1,
                double varargin_2, double varargin_3, double varargin_4,
                const char varargin_5[8], ::coder::array<double, 1U> &x,
                double *M, ::coder::array<double, 1U> &win, double *noverlap,
                double *k, double *L, struct_T *options)
{
  static const char b_cv1[8]{'t', 'w', 'o', 's', 'i', 'd', 'e', 'd'};
  static const char strOpts_f10[8]{'c', 'e', 'n', 't', 'e', 'r', 'e', 'd'};
  static const char strOpts_f2[8]{'o', 'n', 'e', 's', 'i', 'd', 'e', 'd'};
  static const signed char varargin_6[8]{11, 12, 13, 14, 16, 17, 18, 19};
  static const char b_cv[5]{'w', 'h', 'o', 'l', 'e'};
  static const char strOpts_f5[5]{'a', 'd', 'a', 'p', 't'};
  static const char strOpts_f6[5]{'u', 'n', 'i', 't', 'y'};
  static const char strOpts_f7[5]{'e', 'i', 'g', 'e', 'n'};
  static const char b[3]{'o', 'n', 'e'};
  static const char b_b[3]{'t', 'w', 'o'};
  cell_9 inputArgs;
  cell_wrap_21 exclusiveOpts[14];
  cell_wrap_21 r;
  cell_wrap_21 r1;
  cell_wrap_21 r10;
  cell_wrap_21 r11;
  cell_wrap_21 r12;
  cell_wrap_21 r13;
  cell_wrap_21 r2;
  cell_wrap_21 r3;
  cell_wrap_21 r4;
  cell_wrap_21 r5;
  cell_wrap_21 r6;
  cell_wrap_21 r7;
  cell_wrap_21 r8;
  cell_wrap_21 r9;
  double b_index;
  int arg2_size[2];
  int b_i_size[2];
  int i_size[2];
  int b_L;
  int b_M;
  int eint;
  int ret;
  char tmp_data[15];
  char arg2_data[8];
  char options_range[8];
  char c;
  boolean_T guard1{false};
  boolean_T options_centerdc;
  boolean_T result;
  x.set_size(x1.size(1));
  ret = x1.size(1);
  for (int i{0}; i < ret; i++) {
    x[i] = x1[i];
  }
  b_M = x1.size(1);
  hamming(varargin_1, win);
  b_L = win.size(0);
  frexp(static_cast<double>(win.size(0)), &eint);
  inputArgs.f1 = varargin_3;
  inputArgs.f2 = varargin_4;
  options_centerdc = false;
  r.f1.size[0] = 1;
  r.f1.size[1] = 4;
  r.f1.data[0] = 'h';
  r.f1.data[1] = 'a';
  r.f1.data[2] = 'l';
  r.f1.data[3] = 'f';
  r1.f1.size[0] = 1;
  r1.f1.size[1] = 8;
  for (int i{0}; i < 8; i++) {
    c = strOpts_f2[i];
    options_range[i] = c;
    inputArgs.f3[i] = varargin_5[i];
    r1.f1.data[i] = c;
  }
  r2.f1.size[0] = 1;
  r2.f1.size[1] = 5;
  r3.f1.size[0] = 1;
  r3.f1.size[1] = 5;
  r4.f1.size[0] = 1;
  r4.f1.size[1] = 5;
  for (int i{0}; i < 5; i++) {
    c = strOpts_f5[i];
    r2.f1.data[i] = c;
    r3.f1.data[i] = c;
    r4.f1.data[i] = strOpts_f6[i];
  }
  r5.f1.size[0] = 1;
  r5.f1.size[1] = 4;
  r5.f1.data[0] = 'h';
  r5.f1.data[1] = 'a';
  r5.f1.data[2] = 'l';
  r5.f1.data[3] = 'f';
  r6.f1.size[0] = 1;
  r6.f1.size[1] = 8;
  for (int i{0}; i < 8; i++) {
    r6.f1.data[i] = strOpts_f2[i];
  }
  r7.f1.size[0] = 1;
  r7.f1.size[1] = 5;
  for (int i{0}; i < 5; i++) {
    r7.f1.data[i] = b_cv[i];
  }
  r8.f1.size[0] = 1;
  r8.f1.size[1] = 8;
  for (int i{0}; i < 8; i++) {
    r8.f1.data[i] = b_cv1[i];
  }
  r9.f1.size[0] = 1;
  r9.f1.size[1] = 5;
  r10.f1.size[0] = 1;
  r10.f1.size[1] = 5;
  r11.f1.size[0] = 1;
  r11.f1.size[1] = 5;
  for (int i{0}; i < 5; i++) {
    r9.f1.data[i] = strOpts_f6[i];
    c = strOpts_f7[i];
    r10.f1.data[i] = c;
    r11.f1.data[i] = c;
  }
  r12.f1.size[0] = 1;
  r12.f1.size[1] = 8;
  r13.f1.size[0] = 1;
  r13.f1.size[1] = 8;
  for (int i{0}; i < 8; i++) {
    c = strOpts_f10[i];
    r12.f1.data[i] = c;
    r13.f1.data[i] = c;
  }
  exclusiveOpts[0] = r;
  exclusiveOpts[1] = r1;
  exclusiveOpts[2] = r2;
  exclusiveOpts[3] = r3;
  exclusiveOpts[4] = r4;
  exclusiveOpts[5] = r5;
  exclusiveOpts[6] = r6;
  exclusiveOpts[7] = r7;
  exclusiveOpts[8] = r8;
  exclusiveOpts[9] = r9;
  exclusiveOpts[10] = r10;
  exclusiveOpts[11] = r11;
  exclusiveOpts[12] = r12;
  exclusiveOpts[13] = r13;
  ret = 0;
  guard1 = false;
  int exitg1;
  do {
    exitg1 = 0;
    if (ret < 7) {
      boolean_T b_x[3];
      boolean_T b_guard1{false};
      boolean_T exitg2;
      ::coder::internal::b_strcmp(exclusiveOpts[ret].f1.data,
                                  exclusiveOpts[ret].f1.size, inputArgs, b_x);
      result = false;
      eint = 0;
      exitg2 = false;
      while ((!exitg2) && (eint < 3)) {
        if (b_x[eint]) {
          result = true;
          exitg2 = true;
        } else {
          eint++;
        }
      }
      b_guard1 = false;
      if (result) {
        ::coder::internal::b_strcmp(exclusiveOpts[ret + 7].f1.data,
                                    exclusiveOpts[ret + 7].f1.size, inputArgs,
                                    b_x);
        result = false;
        eint = 0;
        exitg2 = false;
        while ((!exitg2) && (eint < 3)) {
          if (b_x[eint]) {
            result = true;
            exitg2 = true;
          } else {
            eint++;
          }
        }
        if (result) {
          exitg1 = 1;
        } else {
          b_guard1 = true;
        }
      } else {
        b_guard1 = true;
      }
      if (b_guard1) {
        ret++;
        guard1 = false;
      }
    } else {
      double b_i_data[19];
      int tmp_size[2];
      signed char i_data[19];
      char b_y1[8];
      boolean_T c_x[19];
      boolean_T exitg2;
      boolean_T guard2{false};
      for (eint = 0; eint < 8; eint++) {
        b_y1[eint] = cv[static_cast<int>(varargin_5[eint])];
      }
      ret = memcmp(&b_y1[0], &b[0], 3);
      guard2 = false;
      if (ret != 0) {
        ret = memcmp(&b_y1[0], &b_b[0], 3);
        if (ret != 0) {
          arg2_size[0] = 1;
          arg2_size[1] = 8;
          for (int i{0}; i < 8; i++) {
            arg2_data[i] = b_y1[i];
          }
        } else {
          guard2 = true;
        }
      } else {
        guard2 = true;
      }
      if (guard2) {
        if ((b_y1[3] == ' ') || (b_y1[3] == '-')) {
          arg2_size[0] = 1;
          arg2_size[1] = 7;
          arg2_data[0] = b_y1[0];
          arg2_data[1] = b_y1[1];
          arg2_data[2] = b_y1[2];
          arg2_data[3] = b_y1[4];
          arg2_data[4] = b_y1[5];
          arg2_data[5] = b_y1[6];
          arg2_data[6] = b_y1[7];
        } else {
          arg2_size[0] = 1;
          arg2_size[1] = 8;
          for (int i{0}; i < 8; i++) {
            arg2_data[i] = b_y1[i];
          }
        }
      }
      validatestring(arg2_data, arg2_size, tmp_data, tmp_size);
      ::coder::internal::c_strcmp(tmp_data, tmp_size, c_x);
      ret = 0;
      eint = 0;
      exitg2 = false;
      while ((!exitg2) && (eint < 19)) {
        if (c_x[eint]) {
          ret++;
          i_data[ret - 1] = static_cast<signed char>(eint + 1);
          if (ret >= 19) {
            exitg2 = true;
          } else {
            eint++;
          }
        } else {
          eint++;
        }
      }
      if (ret < 1) {
        eint = 0;
      } else {
        eint = ret;
      }
      i_size[0] = 1;
      i_size[1] = eint;
      for (int i{0}; i < eint; i++) {
        b_i_data[i] = i_data[i];
      }
      if (eint <= 1) {
        int exitg5;
        ret = 0;
        do {
          exitg5 = 0;
          if (ret < 4) {
            result = false;
            if (eint == 1) {
              b_i_size[0] = 1;
              b_i_size[1] = 1;
              result = (ret + 1 == static_cast<int>(b_i_data[0]));
              result = ::coder::internal::ifWhileCond(
                  (const boolean_T *)&result, b_i_size);
            }
            if (result) {
              ret = 0;
              exitg5 = 1;
            } else {
              ret++;
            }
          } else {
            ret = 0;
            exitg5 = 2;
          }
        } while (exitg5 == 0);
        if (exitg5 != 1) {
          int exitg4;
          do {
            exitg4 = 0;
            if (ret < 3) {
              result = false;
              if (eint == 1) {
                b_i_size[0] = 1;
                b_i_size[1] = 1;
                result = (ret + 5 == static_cast<int>(b_i_data[0]));
                result = ::coder::internal::ifWhileCond(
                    (const boolean_T *)&result, b_i_size);
              }
              if (result) {
                ret = 1;
                exitg4 = 1;
              } else {
                ret++;
              }
            } else {
              result = false;
              if (eint == 1) {
                b_i_size[0] = 1;
                b_i_size[1] = 1;
                result = (b_i_data[0] == 8.0);
                result = ::coder::internal::ifWhileCond(
                    (const boolean_T *)&result, b_i_size);
              }
              exitg4 = 2;
            }
          } while (exitg4 == 0);
          if (exitg4 != 1) {
            if (result) {
              ret = 2;
            } else {
              result = false;
              if (eint == 1) {
                b_i_size[0] = 1;
                b_i_size[1] = 1;
                result = (b_i_data[0] == 9.0);
                result = ::coder::internal::ifWhileCond(
                    (const boolean_T *)&result, b_i_size);
              }
              if (result) {
                ret = 3;
              } else {
                result = false;
                if (eint == 1) {
                  b_i_size[0] = 1;
                  b_i_size[1] = 1;
                  result = (b_i_data[0] == 10.0);
                  result = ::coder::internal::ifWhileCond(
                      (const boolean_T *)&result, b_i_size);
                }
                if (result) {
                  ret = 4;
                } else {
                  ret = 0;
                  int exitg3;
                  do {
                    exitg3 = 0;
                    if (ret < 8) {
                      result = false;
                      if (eint == 1) {
                        b_i_size[0] = 1;
                        b_i_size[1] = 1;
                        result =
                            (varargin_6[ret] == static_cast<int>(b_i_data[0]));
                        result = ::coder::internal::ifWhileCond(
                            (const boolean_T *)&result, b_i_size);
                      }
                      if (result) {
                        ret = 5;
                        exitg3 = 1;
                      } else {
                        ret++;
                      }
                    } else {
                      result = false;
                      if (eint == 1) {
                        b_i_size[0] = 1;
                        b_i_size[1] = 1;
                        result = (b_i_data[0] == 15.0);
                        result = ::coder::internal::ifWhileCond(
                            (const boolean_T *)&result, b_i_size);
                      }
                      if (result) {
                        ret = 6;
                      } else {
                        ret = -1;
                      }
                      exitg3 = 1;
                    }
                  } while (exitg3 == 0);
                }
              }
            }
          }
        }
        switch (ret) {
        case 0: {
          double visitedOpts[16];
          checkUniqueOpts(b_i_data, i_size, &result, visitedOpts, &b_index);
          if (!result) {
            b_i_size[0] = 1;
            b_i_size[1] = eint;
            for (int i{0}; i < eint; i++) {
              result = (b_i_data[0] == 1.0);
            }
            if (!::coder::internal::ifWhileCond((const boolean_T *)&result,
                                                b_i_size)) {
              boolean_T c_i_data;
              for (int i{0}; i < eint; i++) {
                c_i_data = (result || (b_i_data[0] == 2.0));
              }
              b_i_size[0] = 1;
              b_i_size[1] = eint;
              for (int i{0}; i < eint; i++) {
                result = c_i_data;
              }
              if (!::coder::internal::ifWhileCond((const boolean_T *)&result,
                                                  b_i_size)) {
                for (int i{0}; i < 8; i++) {
                  options_range[i] = b_cv1[i];
                }
              }
            }
            guard1 = true;
          }
        } break;
        case 1:
        case 2:
        case 3:
        case 6:
          break;
        case 4: {
          double visitedOpts[16];
          checkUniqueOpts(b_i_data, i_size, &result, visitedOpts, &b_index);
          if (!result) {
            options_centerdc = true;
            guard1 = true;
          }
        } break;
        case 5:
          guard1 = true;
          break;
        }
      }
      exitg1 = 1;
    }
  } while (exitg1 == 0);
  if (guard1) {
    options->nfft = varargin_3;
    options->Fs = varargin_4;
    options->conflevel = rtNaN;
    options->average = true;
    options->maxhold = false;
    options->minhold = false;
    options->MIMO = false;
    options->isNFFTSingle = false;
    options->centerdc = options_centerdc;
    for (int i{0}; i < 8; i++) {
      options->range[i] = options_range[i];
    }
  }
  *k = std::trunc((static_cast<double>(x1.size(1)) - varargin_2) /
                  (static_cast<double>(win.size(0)) - varargin_2));
  *M = b_M;
  *noverlap = varargin_2;
  *L = b_L;
}

} // namespace spectral
} // namespace internal
} // namespace signal
} // namespace coder

//
// File trailer for welchparse.cpp
//
// [EOF]
//
